package com.ztgf.shopping.api.cms.shop;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.shop.*;
import com.ztgf.shopping.models.dto.shop.ShopInfoAuditDTO;
import com.ztgf.shopping.models.service.shop.IShopInfoAuditLogService;
import com.ztgf.shopping.models.service.shop.IShopInfoAuditService;
import com.ztgf.shopping.models.vo.shop.ShopInfoAuditLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 店铺审核日志控制器
 *
 * @author zhanghualang
 * @Date 2020-06-16 16:21:25
 */

@RestController
@RequestMapping("/cms/shopInfoAuditLog")
@Slf4j
@Api(value = "ShopInfoAuditLogController", tags = "店铺审核日志接口")
public class ShopInfoAuditLogController {

    @DubboReference
    private IShopInfoAuditLogService shopInfoAuditLogService;
    @DubboReference
    private IShopInfoAuditService shopInfoAuditService;

    @ApiOperation(value = "注册审核通过日志", notes = "注册审核通过日志")
    @PostMapping(value = "/insertLoginPass")
    public Result insertLoginPass(ShopInfoAuditLoginSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }

        boolean flag = shopInfoAuditLogService.addLoginPass(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "注册审核打回日志", notes = "注册审核打回日志")
    @PostMapping(value = "/insertLoginReturn")
    public Result insertLoginReturn(ShopInfoAuditLoginSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertLoginReturn(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "注册审核拒绝日志，加入黑名单", notes = "注册审核拒绝日志，加入黑名单")
    @PostMapping(value = "/insertLoginReject")
    public Result insertLoginReject(ShopInfoAuditLoginSaveBO saveBO) {
        if (saveBO.getShopAuditId() == null || saveBO.getUserId() == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }

        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertLoginReject(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "开店审核通过日志", notes = "开店审核通过日志")
    @PostMapping(value = "/insertOpenPass")
    public Result insertOpenPass(ShopInfoAuditOpenSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertOpenPass(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "开店审核打回日志", notes = "开店审核打回日志")
    @PostMapping(value = "/insertOpenReturn")
    public Result insertOpenReturn(ShopInfoAuditOpenSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertOpenReturn(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "开店审核拒绝日志，加入黑名单", notes = "开店审核拒绝日志，加入黑名单")
    @PostMapping(value = "/insertOpenReject")
    public Result insertOpenReject(ShopInfoAuditOpenSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertOpenReject(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "资质变更审核通过日志", notes = "资质变更审核通过日志")
    @PostMapping(value = "/insertChangePass")
    public Result insertChangePass(ShopInfoAuditChangeSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertChangePass(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "资质变更审核打回日志", notes = "资质变更审核打回日志")
    @PostMapping(value = "/insertChangeReturn")
    public Result insertChangeReturn(ShopInfoAuditChangeSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertChangeReturn(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "新增品牌审核通过日志", notes = "新增品牌审核通过日志")
    @PostMapping(value = "/insertBrandPass")
    public Result insertBrandPass(ShopInfoAuditBrandSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertBrandPass(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "新增品牌审核打回日志", notes = "新增品牌审核打回日志")
    @PostMapping(value = "/insertBrandReturn")
    public Result insertBrandReturn(ShopInfoAuditBrandSaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertBrandReturn(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "新增品牌类目审核通过日志", notes = "新增品牌类目审核通过日志")
    @PostMapping(value = "/insertCategoryPass")
    public Result insertCategoryPass(ShopInfoAuditCategorySaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertCategoryPass(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "新增品牌类目审核打回日志", notes = "新增品牌类目审核打回日志")
    @PostMapping(value = "/insertCategoryReturn")
    public Result insertCategoryReturn(ShopInfoAuditCategorySaveBO saveBO) {
        ShopInfoAuditDTO dto = shopInfoAuditService.selectById(saveBO.getShopAuditId());
        if (!dto.getStatus().equals(0) && !dto.getStatus().equals(4)) {
            return new Result<>(CodeEnum.FAIL_100046);
        }
        boolean flag = shopInfoAuditLogService.insertCategoryReturn(saveBO);
        if (flag) {
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100014);
        }
    }

    @ApiOperation(value = "店铺审核日志列表", notes = "店铺审核日志列表")
    @PostMapping("/queryPageList")
    public Result<Page<ShopInfoAuditLogVO>> queryPageList(ShopInfoAuditLogBO bo) {
        Page<ShopInfoAuditLogVO> page = shopInfoAuditLogService.queryPageList(bo);

        return new Result<>(page);
    }

    @ApiOperation(value = "注册审核操作", notes = "注册审核操作")
    @PostMapping(value = "/registerAudit")
    public Result registerAudit(String loginVO) {
        return shopInfoAuditLogService.insertRegisterAudit(loginVO);
    }

    @ApiOperation(value = "店铺审核操作", notes = "店铺审核操作")
    @PostMapping(value = "/shopAudit")
    public Result shopAudit(String shopVO) {
        return shopInfoAuditLogService.insertShopAudit(shopVO);
    }

    @ApiOperation(value = "资质变更审核操作", notes = "资质变更审核操作")
    @PostMapping(value = "/changeAudit")
    public Result changeAudit(String shopVO) {
        return shopInfoAuditLogService.insertchangeAudit(shopVO);
    }

    @ApiOperation(value = "新增品牌审核操作", notes = "新增品牌审核操作")
    @PostMapping(value = "/addBrandAudit")
    public Result addBrandAudit(String shopVO) {
        return shopInfoAuditLogService.insertaddBAudit(shopVO);
    }

    @ApiOperation(value = "类目变更审核通过", notes = "类目变更审核通过")
    @PostMapping(value = "/addCategoryAudit")
    public Result addCategoryAudit(String shopVO) {
        return shopInfoAuditLogService.addCategoryAudit(shopVO);
    }

    @PostMapping(value = "/updateShopAudit")
    @ApiOperation(value = "店铺变更审核", notes = "店铺变更审核")
    public Result<?> updateShopAudit(String shopVO) {
        return shopInfoAuditLogService.updateShopAudit(shopVO);
    }
}
